package edu.java.lectures.lec13.equals;

import junit.framework.TestCase;

public class PersonEqualsTest extends TestCase {

    private Person pesho;
    private Person mincho;
    private Person peshoCopy;
    private Person peshoCopyCopy;

    @Override
    protected void setUp() throws Exception {
	pesho = new Person("Pesho", 21);
	mincho = new Person("Mincho", 32);
	peshoCopy = new Person("Pesho", 21);
	peshoCopyCopy = new Person("Pesho", 21);
    }

    // It is reflexive: for any non-null reference value x, x.equals(x) should
    // return true.
    public void testIsEqualsReflexive() {
	assertTrue(pesho.equals(pesho));
    }

    // It is symmetric: for any non-null reference values x and y, x.equals(y)
    // should return true if and only if y.equals(x) returns true.
    public void testIsEqualsSymmetric() {
	assertTrue(pesho.equals(peshoCopy) && peshoCopy.equals(pesho));
	assertFalse(pesho.equals(mincho) | mincho.equals(pesho));
    }

    // It is transitive: for any non-null reference values x, y, and z, if
    // x.equals(y) returns true and y.equals(z) returns true, then x.equals(z)
    // should return true.
    public void testIsEqualsTransitive() {
	assertTrue(pesho.equals(peshoCopy) && peshoCopy.equals(peshoCopyCopy)
		&& peshoCopyCopy.equals(pesho));
    }

    // It is consistent: for any non-null reference values x and y, multiple
    // invocations of x.equals(y) consistently return true or consistently
    // return false, provided no information used in equals comparisons on the
    // objects is modified.
    public void testIsEqualsConsistent() {
	for (int i = 0; i < 1000; i++) {
	    assertTrue(pesho.equals(peshoCopy));
	    assertFalse(pesho.equals(mincho));
	}
    }

    // For any non-null reference value x, x.equals(null) should return false.
    public void testIsNotEqualsToNull() {
	assertFalse(pesho.equals(null));
    }

    @Override
    protected void tearDown() throws Exception {
	pesho = null;
	mincho = null;
	peshoCopy = null;
	peshoCopyCopy = null;
    }
}
